package com.yyds.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yyds.common.MyJSON;
import com.yyds.mapper.TravelStaffMapper;
import com.yyds.pojo.TravelStaff;
import com.yyds.service.TravelStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 落水无痕
 *
 * @PACKAGE_NAME: com.yyds.service.impl
 * @NAME: TravelStaffServiceImpl
 * @USER: me
 * @DATE: 2022/10/14
 * @TIME: 21:30
 * @YEAR: 2022
 * @DAY: 14
 * @DAY_NAME_SHORT: 周五
 * @DAY_NAME_FULL: 星期五
 **/
@Service("travelStaffService")
public class TravelStaffServiceImpl implements TravelStaffService {
    @Autowired
  private TravelStaffMapper travelStaffMapper;

    @Override
    public int addtravelstaff(TravelStaff travelStaff) {

        return travelStaffMapper.addtravelstaff(travelStaff);
    }

    @Override
    public int deletetravelstaff(Integer staff_id) {

        return travelStaffMapper.deletetravelstaff(staff_id);
    }

    @Override
    public int updatetravelstaff(TravelStaff travelStaff) {

        return travelStaffMapper.updatetravelstaff(travelStaff);
    }

    @Override
    public MyJSON<TravelStaff> queryalltravelstaffs(Map<String, Object> queryall) {

        Integer page = Integer.parseInt(queryall.get("page")+"");
        Integer limit = Integer.parseInt(queryall.get("limit")+"");
        PageHelper.startPage(page,limit);
        List<TravelStaff> queryalltravelstaff =  travelStaffMapper.queryalltravelstaffs(queryall);
        // mybatis 的分页数据结构
        PageInfo<TravelStaff>  travelStaffPageInfo= new PageInfo<>(queryalltravelstaff);
        // 把mybatis 的分页数据结构中的 数据 封装到 layui的 分页数据结构中
        MyJSON<TravelStaff> staffMyJSON = new MyJSON<>();
        staffMyJSON.setCode(0);
        staffMyJSON.setMsg("学生分页列表数据");
        staffMyJSON.setCount(travelStaffPageInfo.getTotal());  // 总记录数
        staffMyJSON.setData(travelStaffPageInfo.getList());  // 分页列表数据
        return staffMyJSON;
    }

    @Override
    public Integer deletestravelstaffs(String str) {
        String[] strs = str.split("-");
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < strs.length; i++) {
            list.add(Integer.parseInt(strs[i]));
        }
        return travelStaffMapper.deletestravelstaffs(list);
    }

    @Override
    public MyJSON<TravelStaff> queryalltravelstaff(Map<String, Object> queryall) {
        Integer page = Integer.parseInt(queryall.get("page")+"");
        Integer limit = Integer.parseInt(queryall.get("limit")+"");
        PageHelper.startPage(page,limit);
        List<TravelStaff> queryalltravelstaff =  travelStaffMapper.queryalltravelstaff(queryall);
        // mybatis 的分页数据结构
        PageInfo<TravelStaff>  travelStaffPageInfo= new PageInfo<>(queryalltravelstaff);
        // 把mybatis 的分页数据结构中的 数据 封装到 layui的 分页数据结构中
        MyJSON<TravelStaff> staffMyJSON = new MyJSON<>();
        staffMyJSON.setCode(0);
        staffMyJSON.setMsg("学生分页列表数据");
        staffMyJSON.setCount(travelStaffPageInfo.getTotal());  // 总记录数
        staffMyJSON.setData(travelStaffPageInfo.getList());  // 分页列表数据
        return staffMyJSON;
    }
}
